﻿using System;
using System.Collections.Generic;
using System.Text;
using Microsoft.Practices.EnterpriseLibrary.Logging;
using System.Configuration;
using Microsoft.Practices.EnterpriseLibrary.ExceptionHandling;

namespace PMT.Common
{
    /// <summary>
    /// This class handles exceptions and log messages
    /// </summary>
    public class Loggers
    {
        /// <summary>
        /// Write a message to log file
        /// </summary>
        /// <param name="message"></param>
        public static void WriteLog(string message)
        {
            try
            {
                LogEntry entry = new LogEntry();
                entry.Message = message;
                entry.TimeStamp = DateTime.Now;
                Logger.Write(entry);
            }
            catch (ConfigurationErrorsException ex)
            {
                throw;
            }
        }
        /// <summary>
        /// Write an exception to error log file
        /// </summary>
        /// <param name="ex"></param>
        public static void WriteLog(Exception ex)
        {
            try
            {
                ExceptionPolicy.HandleException(ex, "NoneExceptionPolicy");
            }
            catch (ConfigurationErrorsException exConfig)
            {
                throw;
            }
        }
    }
}
